﻿using System;

namespace EmbeddedSharp.Core.Functoin.String {

    /// <summary>
    /// Get the number of characters in a string.
    /// 
    /// Syntax: <i>Length(expr)</i>
    /// 
    /// Example:
    /// a = Length("Hello"); # 5
    /// </summary>
    public class LengthNode : FuncNode {

        public LengthNode()
            : base() {
            base.Value = "length";
        }

        public override object Evaluate() {
            if (Parameters.Count == 0) {
                return "usage: length(\"string\")";
            }

            return Parameters[0].Evaluate().ToString().Length;
        }
    }
}
